package com.cqapp.widget.ui.image;

import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.cqapp.widget.R;

/*****
 *
 * ImageFragment 配合ViewPager使用，实现图片的滑动
 */
public class ImageFragment extends Fragment {

    private ImageViewModel mViewModel;

    public ImageFragment(ImageViewModel mViewModel) {
        this.mViewModel = mViewModel;
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        View root =inflater.inflate(R.layout.fragment_image, container, false);
        ImageView imageView = root.findViewById(R.id.iv_main_pic);

         //使用Glide进行加载
         Glide.with(getContext()).load(mViewModel.getImageId()).into(imageView);
        return  root;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
//      mViewModel = ViewModelProviders.of(this).get(ImageViewModel.class);
        // TODO: Use the ViewModel
    }

}
